package com.jhws.core.db;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowMapper;

public class BeanResultSetExtrator<T> implements ResultSetExtractor<T>{

	private final RowMapper<T> rowMapper;
	
	public BeanResultSetExtrator(Class<T> c) {
		this.rowMapper = BeanPropertyRowMapper.newInstance(c);
	}

	@Override
	public T extractData(ResultSet rs) throws SQLException {
		if (rs.next()) {
			return this.rowMapper.mapRow(rs, 0);
		}else{
			return null;
		}
	}


}
